// PageGeneral.cpp : implementation file
//

#include "stdafx.h"
#include "ECGWorkStation.h"
#include "PageGeneral.h"
#include "..\public\pubfun\inireadwrite\inireadwrite.h"
#include "Globals.h"
#include "..\public\pubfun\PathDialog\PathDialog.h"

#include "MyFileDialog.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPageGeneral property page
#define SET_BUTTON_COLOR(btnST, crColor) \
	btnST.SetColor(CButtonST::BTNST_COLOR_BK_IN, crColor); \
	btnST.SetColor(CButtonST::BTNST_COLOR_BK_OUT, crColor); \
	btnST.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, crColor); 

IMPLEMENT_DYNCREATE(CPageGeneral, CPropertyPage)

CPageGeneral::CPageGeneral() : CPropertyPage(CPageGeneral::IDD)
{
	//{{AFX_DATA_INIT(CPageGeneral)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CPageGeneral::~CPageGeneral()
{
}

void CPageGeneral::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageGeneral)
	DDX_Control(pDX, IDC_BUTTON_P, m_btnAnnColorP);
	DDX_Control(pDX, IDC_BUTTON_Q, m_btnAnnColorQ);
	DDX_Control(pDX, IDC_BUTTON_R, m_btnAnnColorR);
	DDX_Control(pDX, IDC_BUTTON_S, m_btnAnnColorS);
	DDX_Control(pDX, IDC_BUTTON_R1, m_btnAnnColorR1);
	DDX_Control(pDX, IDC_BUTTON_S1, m_btnAnnColorS1);
	DDX_Control(pDX, IDC_BUTTON_T, m_btnAnnColorT);
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageGeneral, CPropertyPage)
	//{{AFX_MSG_MAP(CPageGeneral)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_SHORTTERM, OnButtonShortterm)
	ON_BN_CLICKED(IDC_BUTTON_P, OnButtonP)
	ON_BN_CLICKED(IDC_BUTTON_Q, OnButtonQ)
	ON_BN_CLICKED(IDC_BUTTON_R, OnButtonR)
	ON_BN_CLICKED(IDC_BUTTON_S, OnButtonS)
	ON_BN_CLICKED(IDC_BUTTON_R1, OnButtonR1)
	ON_BN_CLICKED(IDC_BUTTON_S1, OnButtonS1)
	ON_BN_CLICKED(IDC_BUTTON_T, OnButtonT)
	ON_BN_CLICKED(IDC_BUTTON_DATABASE, OnButtonDatabase)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageGeneral message handlers

void CPageGeneral::OnDestroy() 
{
	CPropertyPage::OnDestroy();
	
	((CEdit*)GetDlgItem(IDC_EDIT_SHORTTERM))->GetWindowText(strShortTerm);
	((CEdit*)GetDlgItem(IDC_EDIT_DATABASE))->GetWindowText(strDataBaseName);
	((CEdit*)GetDlgItem(IDC_EDIT_BEGIN_TIME))->GetWindowText(strPrintBeginTime);

	CString strTemp = "";
	((CEdit*)GetDlgItem(IDC_EDIT_PRINTFONTSIZE))->GetWindowText(strTemp);
	strTemp.TrimLeft(); strTemp.TrimRight();
	nPrintFontSize = atoi(strTemp);

//	if (((CButton*)GetDlgItem(IDC_CHECK_WAVEFORM))->GetCheck()) {
//		strReportWaveForm = "TRUE";
//	}else{
//		strReportWaveForm = "FALSE";
//	}

	if (((CButton*)GetDlgItem(IDC_CHECK_PRINTPREV))->GetCheck()) {
		strReportPrintPrev = "TRUE";
	}else{
		strReportPrintPrev = "FALSE";
	}

//	if (((CButton*)GetDlgItem(IDC_CHECK_SINGLE))->GetCheck()) {
//		strReportWaveFormAnalyse = "TRUE";
//	}else{
//		strReportWaveFormAnalyse = "FALSE";
//	}

//	if (((CButton*)GetDlgItem(IDC_CHECK_ANALYSE))->GetCheck()) {
//		strReportAnalyse = "TRUE";
//	}else{
//		strReportAnalyse = "FALSE";
//	}
	
	if (((CButton*)GetDlgItem(IDC_CHECK_PRINTCOLOR))->GetCheck()) {
		strReportColor = "TRUE";
	}else{
		strReportColor = "FALSE";
	}

	if (((CButton*)GetDlgItem(IDC_QUICK_PRINT))->GetCheck()) {
		strQuickPrint = "TRUE";
	}else{
		strQuickPrint = "FALSE";
	}

	if (((CButton*)GetDlgItem(IDC_CHECK_CONVERTBMP))->GetCheck()) {
		strConvertToBMP = "TRUE";
	}else{
		strConvertToBMP = "FALSE";
	}

	if (((CButton*)GetDlgItem(IDC_CHECK_CONVERTJPG))->GetCheck()) {
		strConvertToJPG = "TRUE";
	}else{
		strConvertToJPG = "FALSE";
	}


	if (((CButton*)GetDlgItem(IDC_CHECK_DISP_PATIENT_INFO))->GetCheck()) {
		strDispPatinfo = "TRUE";
	}else{
		strDispPatinfo = "FALSE";
	}
 
	COLORREF cr;
	((CButtonST*)GetDlgItem(IDC_BUTTON_P))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorP = ConvertColorREFToString(cr);

	((CButtonST*)GetDlgItem(IDC_BUTTON_Q))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorQ = ConvertColorREFToString(cr);

	((CButtonST*)GetDlgItem(IDC_BUTTON_R))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorR = ConvertColorREFToString(cr);

	((CButtonST*)GetDlgItem(IDC_BUTTON_S))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorS = ConvertColorREFToString(cr);

	((CButtonST*)GetDlgItem(IDC_BUTTON_R1))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorR1 = ConvertColorREFToString(cr);

	((CButtonST*)GetDlgItem(IDC_BUTTON_S1))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorS1 = ConvertColorREFToString(cr);

	((CButtonST*)GetDlgItem(IDC_BUTTON_T))->GetColor(CButtonST::BTNST_COLOR_BK_IN, &cr);
	strAnnColorT = ConvertColorREFToString(cr);

	nPrintGrid = ((CComboBox*)GetDlgItem(IDC_COMBO_GRID))->GetCurSel();
	nWaveFormPrint = ((CComboBox*)GetDlgItem(IDC_COMBO_WAVEFORMPRINT))->GetCurSel();
}

BOOL CPageGeneral::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	LoadSetting();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPageGeneral::OnButtonShortterm() 
{
	CPathDialog dlg("Open");
	if(dlg.DoModal() == IDOK)
	{
		strShortTerm = dlg.GetPathName();
		((CEdit*)GetDlgItem(IDC_EDIT_SHORTTERM))->SetWindowText(strShortTerm);
	}
}
void CPageGeneral::OnButtonDatabase() 
{
	TCHAR szModule[_MAX_PATH];
	CString szFilter(_T("Access database(*.mdb)|*.mdb|all files(*.*)|*.*|"));
	CString szExt(_T("mdb"));

	//Get Current Directory
	CString strDataBaseName = "";
	GetCurrentDirectory(_MAX_PATH, szModule);
	CMyFileDialog dlg(TRUE, szExt, "", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter);
		dlg.m_ofn.lpstrTitle  = "Open";
	if(dlg.DoModal() == IDOK)
	{
		strDataBaseName = dlg.GetPathName();
		((CEdit*)GetDlgItem(IDC_EDIT_DATABASE))->SetWindowText(strDataBaseName);
	}
	//Set Current Directory
	SetCurrentDirectory(szModule);
}

void CPageGeneral::OnButtonP() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_P)), colorDlg.GetColor());
	}
}

void CPageGeneral::OnButtonQ() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_Q)), colorDlg.GetColor());
	}
	
}

void CPageGeneral::OnButtonR() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_R)), colorDlg.GetColor());
	}
	
}

void CPageGeneral::OnButtonS() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_S)), colorDlg.GetColor());
	}
	
}

void CPageGeneral::OnButtonR1() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_R1)), colorDlg.GetColor());
	}
	
}

void CPageGeneral::OnButtonS1() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_S1)), colorDlg.GetColor());
	}
}

void CPageGeneral::OnButtonT() 
{
	CColorDialog colorDlg;
	if(colorDlg.DoModal() == IDOK){
		SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_T)), colorDlg.GetColor());
	}
	
}
void CPageGeneral::LoadSetting()
{
	CIniReadWrite::GetMe()->LoadString(DEF_GENERAL_SETTING, DEF_SHORTTERM, &strShortTerm);
	((CEdit*)GetDlgItem(IDC_EDIT_SHORTTERM))->SetWindowText(strShortTerm);
	CIniReadWrite::GetMe()->LoadString(DEF_GENERAL_SETTING, DEF_DB_CONNECTION, &strDataBaseName);
	((CEdit*)GetDlgItem(IDC_EDIT_DATABASE))->SetWindowText(strDataBaseName);

	CIniReadWrite::GetMe()->LoadString(DEF_GENERAL_SETTING, DEF_PRINT_BEGIN_TIME, &strPrintBeginTime);
	((CEdit*)GetDlgItem(IDC_EDIT_BEGIN_TIME))->SetWindowText(strPrintBeginTime);

	if(CIniReadWrite::GetMe()->LoadInt(DEF_GENERAL_SETTING, DEF_WAVEFORMPRINT, &nWaveFormPrint)){
		((CComboBox*)GetDlgItem(IDC_COMBO_WAVEFORMPRINT))->SetCurSel(nWaveFormPrint);
	}else{
		nWaveFormPrint = 0;
		((CComboBox*)GetDlgItem(IDC_COMBO_WAVEFORMPRINT))->SetCurSel(nWaveFormPrint);
	}

//	CIniReadWrite::GetMe()->LoadString(DEF_REPORT, DEF_REPORT_WAVEFORM, &strReportWaveForm);
//	if (!strReportWaveForm.CompareNoCase("TRUE")) {
//		((CButton*)GetDlgItem(IDC_CHECK_WAVEFORM))->SetCheck(TRUE);
//	}else ((CButton*)GetDlgItem(IDC_CHECK_WAVEFORM))->SetCheck(FALSE);

//	CIniReadWrite::GetMe()->LoadString(DEF_REPORT, DEF_REPORT_WAVEFORM_ANALYSE, &strReportWaveFormAnalyse);
//	if (!strReportWaveFormAnalyse.CompareNoCase("TRUE")) {
//		((CButton*)GetDlgItem(IDC_CHECK_SINGLE))->SetCheck(TRUE);
//	}else ((CButton*)GetDlgItem(IDC_CHECK_SINGLE))->SetCheck(FALSE);
//
//	CIniReadWrite::GetMe()->LoadString(DEF_REPORT, DEF_REPORT_ANALYSE, &strReportAnalyse);
//	if (!strReportAnalyse.CompareNoCase("TRUE")) {
//		((CButton*)GetDlgItem(IDC_CHECK_ANALYSE))->SetCheck(TRUE);
//	}else ((CButton*)GetDlgItem(IDC_CHECK_ANALYSE))->SetCheck(FALSE);

	CIniReadWrite::GetMe()->LoadString(DEF_REPORT, DEF_REPORT_PRINTPREV, &strReportPrintPrev);
	if (!strReportPrintPrev.CompareNoCase("TRUE")) {
		((CButton*)GetDlgItem(IDC_CHECK_PRINTPREV))->SetCheck(TRUE);
	}else ((CButton*)GetDlgItem(IDC_CHECK_PRINTPREV))->SetCheck(FALSE);

	CIniReadWrite::GetMe()->LoadString(DEF_REPORT, DEF_REPORT_COLOR, &strReportColor);
	if (!strReportColor.CompareNoCase("TRUE")) {
		((CButton*)GetDlgItem(IDC_CHECK_PRINTCOLOR))->SetCheck(TRUE);
	}else ((CButton*)GetDlgItem(IDC_CHECK_PRINTCOLOR))->SetCheck(FALSE);

	CIniReadWrite::GetMe()->LoadString(DEF_REPORT, DEF_QUICK_PRINT, &strQuickPrint);
	if (!strQuickPrint.CompareNoCase("TRUE")) {
		((CButton*)GetDlgItem(IDC_QUICK_PRINT))->SetCheck(TRUE);
	}else ((CButton*)GetDlgItem(IDC_QUICK_PRINT))->SetCheck(FALSE);

	CIniReadWrite::GetMe()->LoadString(DEF_GENERAL_SETTING, DEF_CONVERT_TO_BMP, &strConvertToBMP);
	if (!strConvertToBMP.CompareNoCase("TRUE")) {
		((CButton*)GetDlgItem(IDC_CHECK_CONVERTBMP))->SetCheck(TRUE);
	}else ((CButton*)GetDlgItem(IDC_CHECK_CONVERTBMP))->SetCheck(FALSE);


	CIniReadWrite::GetMe()->LoadString(DEF_GENERAL_SETTING, DEF_CONVERT_TO_JPG, &strConvertToJPG);
	if (!strConvertToJPG.CompareNoCase("TRUE"))
	{
 		((CButton*)GetDlgItem(IDC_CHECK_CONVERTJPG))->SetCheck(TRUE);
	}
	else
	{
   		((CButton*)GetDlgItem(IDC_CHECK_CONVERTJPG))->SetCheck(FALSE);
	}


	
	CIniReadWrite::GetMe()->LoadString(DEF_GENERAL_SETTING, DEF_GENERAL_SHOWPATINFO_IN_NET_MODEL, &strDispPatinfo);
	if (!strDispPatinfo.CompareNoCase("TRUE")) 
	{
		((CButton*)GetDlgItem(IDC_CHECK_DISP_PATIENT_INFO))->SetCheck(TRUE);
	}else ((CButton*)GetDlgItem(IDC_CHECK_DISP_PATIENT_INFO))->SetCheck(FALSE);


	CIniReadWrite::GetMe()->LoadInt(DEF_REPORT, DEF_REPORT_FONTSIZE, &nPrintFontSize);
	if (nPrintFontSize <= 0 || nPrintFontSize > 50) nPrintFontSize = 12;

	CString strTemp = "";
	strTemp.Format("%d", nPrintFontSize);
	((CEdit*)GetDlgItem(IDC_EDIT_PRINTFONTSIZE))->SetWindowText(strTemp);

	COLORREF cr;
	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_P, &strAnnColorP);
	cr = ConvertStringToColorREF(strAnnColorP);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_P)), cr);

	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_Q, &strAnnColorQ);
	cr = ConvertStringToColorREF(strAnnColorQ);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_Q)), cr);

	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_R, &strAnnColorR);
	cr = ConvertStringToColorREF(strAnnColorR);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_R)), cr);

	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_S, &strAnnColorS);
	cr = ConvertStringToColorREF(strAnnColorS);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_S)), cr);

	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_R1, &strAnnColorR1);
	cr = ConvertStringToColorREF(strAnnColorR1);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_R1)), cr);

	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_S1, &strAnnColorS1);
	cr = ConvertStringToColorREF(strAnnColorS1);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_S1)), cr);

	CIniReadWrite::GetMe()->LoadString(DEF_ANN_COLOR, DEF_ANN_COLOR_T, &strAnnColorT);
	cr = ConvertStringToColorREF(strAnnColorT);
	SET_BUTTON_COLOR((*(CButtonST*)GetDlgItem(IDC_BUTTON_T)), cr);

	CIniReadWrite::GetMe()->LoadInt(DEF_REPORT, DEF_REPORT_GRID, &nPrintGrid);
	if(nPrintGrid < 0 || nPrintGrid > 1) nPrintGrid = 0;
	((CComboBox*)GetDlgItem(IDC_COMBO_GRID))->SetCurSel(nPrintGrid);
}

void CPageGeneral::SaveSetting()
{
	CIniReadWrite::GetMe()->SaveString(DEF_GENERAL_SETTING, DEF_PRINT_BEGIN_TIME, strPrintBeginTime);
	CIniReadWrite::GetMe()->SaveString(DEF_GENERAL_SETTING, DEF_SHORTTERM, strShortTerm);
	CIniReadWrite::GetMe()->SaveString(DEF_REPORT, DEF_REPORT_ANALYSE, strReportAnalyse);
	CIniReadWrite::GetMe()->SaveString(DEF_REPORT, DEF_REPORT_WAVEFORM, strReportWaveForm);
	CIniReadWrite::GetMe()->SaveString(DEF_REPORT, DEF_REPORT_WAVEFORM_ANALYSE, strReportWaveFormAnalyse);
	CIniReadWrite::GetMe()->SaveString(DEF_REPORT, DEF_REPORT_PRINTPREV, strReportPrintPrev);
	CIniReadWrite::GetMe()->SaveInt(DEF_REPORT, DEF_REPORT_FONTSIZE, nPrintFontSize);
	CIniReadWrite::GetMe()->SaveString(DEF_REPORT, DEF_REPORT_COLOR, strReportColor);
	CIniReadWrite::GetMe()->SaveString(DEF_REPORT, DEF_QUICK_PRINT, strQuickPrint);
	CIniReadWrite::GetMe()->SaveString(DEF_GENERAL_SETTING, DEF_CONVERT_TO_BMP, strConvertToBMP);
	CIniReadWrite::GetMe()->SaveString(DEF_GENERAL_SETTING, DEF_CONVERT_TO_JPG, strConvertToJPG);



	CIniReadWrite::GetMe()->SaveString(DEF_GENERAL_SETTING, DEF_GENERAL_SHOWPATINFO_IN_NET_MODEL, strDispPatinfo);

	
	
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_P, strAnnColorP);
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_Q, strAnnColorQ);
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_R, strAnnColorR);
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_S, strAnnColorS);
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_R1, strAnnColorR1);
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_S1, strAnnColorS1);
	CIniReadWrite::GetMe()->SaveString(DEF_ANN_COLOR, DEF_ANN_COLOR_T, strAnnColorT);

	CIniReadWrite::GetMe()->SaveString(DEF_GENERAL_SETTING, DEF_DB_CONNECTION, strDataBaseName);
	CIniReadWrite::GetMe()->SaveInt(DEF_REPORT, DEF_REPORT_GRID, nPrintGrid);
	CIniReadWrite::GetMe()->SaveInt(DEF_GENERAL_SETTING, DEF_WAVEFORMPRINT, nWaveFormPrint);
}


